package com.example.chain.product;

public abstract class Handler {
    protected Handler next;
    public void next(Handler next) {
        this.next = next;
    }
    public abstract String doHandler(UserAccount user);

    public static class Builder{
        private Handler head;
        private Handler tail;

        public Builder add(Handler handler) {

            // 第一次添加进来，头节点为空，设置头结点=尾结点
            if (head == null) {
                this.head = this.tail = handler;
            } else {
                this.tail.next=handler;
                this.tail = handler;
            }
            return this;
        }

        public Handler build(){
            return this.head;
        }
    }
}
